package com.menglei.dailytasks.m0716;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;

import com.menglei.dailytasks.R;

public class SqlLiteActivity extends AppCompatActivity {

    private static final String TAG = "SqlLiteActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sql_lite);
        initView();
    }

    private void initView() {
        DBHelper dbHelper = new DBHelper(this, "test_db", null, 1);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("name", "zhangQiang");
        db.insert("user", null, values);
        Cursor cursor = db.query("user", new String[]{"name"}, null, null, null, null, null);
        while (cursor.moveToNext()) {
            String name = cursor.getString(cursor.getColumnIndex("name"));
            Log.i(TAG, name);
        }
    }
}